package demo1;

import java.util.Arrays;


public class MyStack {

    public int[] elem;
    public int usedSize;

    public MyStack(){
        this.elem = new int[5];
        this.usedSize = 0 ;
    }

    public int size(){
         return this.usedSize;
    }

    public boolean empty(){
         return this.usedSize==0;
    }

    public int peek(){
         return this.elem[this.usedSize-1];
    }

    private boolean isFull(){
        return this.elem.length == this.usedSize;
    }

    public int push(int key){
         if(isFull()){
            this.elem = Arrays.copyOf(this.elem,2*this.elem.length);
         }
         this.elem[usedSize++] = key;
         return key;
    }

    public int pop(){
         int ret = this.elem[this.usedSize-1];
         this.usedSize--;
         return ret;
    }

}
